#pragma once

#include "NFServerComm/NFServerCommon/NFIDescStore.h"
#include "NFServerComm/NFServerCommon/NFIDescTemplate.h"
#include "NFLogicCommon/NFDescStoreMacrosDefine.h"
#include "NFLogicCommon/NFDescStoreTypeDefines.h"
#include "E_Welfare.nanopb.h"
#ifndef MAX_WELFARE_WELFARENODE_NUM
#define MAX_WELFARE_WELFARENODE_NUM 20
#endif

struct WelfareNodeWelfareIdNodeId
{
	WelfareNodeWelfareIdNodeId()
	{
		if (EN_OBJ_MODE_INIT == NFShmMgr::Instance()->GetCreateMode()) {
			CreateInit();
		}
		else {
			ResumeInit();
		}
	}
	int CreateInit()
	{
		m_welfareId=0;
		m_nodeId=0;
		return 0;
	}
	int ResumeInit()
	{
		return 0;
	}
	int64_t m_welfareId;
	int64_t m_nodeId;
	bool operator==(const WelfareNodeWelfareIdNodeId& data) const
	{
		 return m_welfareId== data.m_welfareId && m_nodeId== data.m_nodeId;
	}
	std::string ToString() const
	{
		std::stringstream ios;
		ios << m_welfareId;
		ios << ",";
		ios << m_nodeId;
		return ios.str();
	}
};

namespace std
{
	template<>
	struct hash<WelfareNodeWelfareIdNodeId>
	{
		size_t operator()(const WelfareNodeWelfareIdNodeId& data) const
		{
			return NFHash::hash_combine(data.m_welfareId,data.m_nodeId);
		}
	};
}


class WelfareNodeDesc : public NFI_DESC_TEMPLATE_MACRO(WelfareNodeDesc, E_WelfareNode, EOT_CONST_WELFARE_WELFARENODE_DESC_ID, MAX_WELFARE_WELFARENODE_NUM)
public:
	WelfareNodeDesc();
	virtual ~WelfareNodeDesc();
	int CreateInit();
	int ResumeInit();
public:
	int Load(NFResDb *pDB) override;
	int LoadDB(NFResDb *pDB) override;
	int CheckWhenAllDataLoaded() override;
	std::vector<const E_WelfareNode*> GetDescByWelfareId(int64_t welfareId) const;
	const E_WelfareNode* GetDescByWelfareIdNodeId(int64_t welfareId, int64_t nodeId);
private:
	NFShmHashMultiMap<int64_t, uint64_t, MAX_WELFARE_WELFARENODE_NUM> m_welfareIdIndexMap;
	NFShmHashMap<WelfareNodeWelfareIdNodeId, uint64_t, MAX_WELFARE_WELFARENODE_NUM> m_welfareIdNodeIdComIndexMap;
};
